package api

import (
	"blogdemo/gin/errmsg"
	"blogdemo/gin/model"
	"github.com/gin-gonic/gin"
)

// ViewArticle 阅读博客
func ViewArticle(c *gin.Context) {
	var art model.Article
	// 绑定数据模型
	_ = c.ShouldBind(&art)

	var resart []model.Article
	var flag bool
	resart, flag = model.SearchArticle(art.Title)
	if !flag {
		c.JSON(400, gin.H{
			"status": errmsg.ARTICLE_NOSER,
			"data":   resart,
			"msg":    errmsg.GetErrMsg(errmsg.ARTICLE_NOSER),
		})
		c.Abort()
		return
	}
	c.JSON(200, gin.H{
		"status": errmsg.SUCCESS,
		"data":   resart,
		"msg":    errmsg.GetErrMsg(errmsg.SUCCESS),
	})
}
